#include <vector>
#include <set>
#include <iostream>
#include <unordered_map>
using namespace std;

bool checkPossibility(vector<int>& nums) {
    int flag = 0; int preNum = -100000;
    for(int i = 0; i < nums.size()-1; i++){
        if(nums[i] > nums[i+1]){
            if(preNum <= nums[i+1] && flag == 0){
                flag++;
            }else if(i+2 < nums.size() && nums[i] <= nums[i+2] && flag == 0){
                flag++;
            }else if(i+2 >= nums.size() && flag == 0){
                return true;
            }else{
                return false;
            }
        }
        preNum = nums[i];
    }
    return true;
}

int main(){
    vector<int> nums = { 5,7,1,8 };
    cout << checkPossibility(nums) << endl;
    return 0;
}